{__NOLAYOUT__}
<link rel="stylesheet" href="assets/store/css/amazeui.min.css"/>
<link rel="stylesheet" href="assets/store/css/app.css"/>
<link rel="stylesheet" href="//at.alicdn.com/t/font_783249_t6knt0guzo.css">
<script src="assets/store/js/jquery.min.js"></script>
<script src="assets/layer/layer.js"></script>
<script src="assets/store/js/jquery.form.min.js"></script>
<script src="assets/store/js/amazeui.min.js"></script>
<script src="assets/store/js/webuploader.html5only.js"></script>
<script src="assets/store/js/art-template.js"></script>
<script src="assets/store/js/app.js"></script>
<script src="assets/store/js/file.library.js"></script>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">选择用户成为'<?= $user->nickName ?>'的下级</div>
                </div>
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-9 ">
                    <form class="am-form toolbar-form fr am-form-horizontal" action="">
                        <input type="hidden" name="s"
                               value="/store/user/unbind/userId/<?= $user['user_id'] ?>">

                        <div class="am-form-group am-fl">
                            <select id="gender"
                                    data-am-selected="{searchBox: 0, btnSize: 'sm',  placeholder:'请选择性别'}"
                                    name="level">
                                <option value="0" <?= !isset($_GET['level']) || !$_GET['level'] ? "selected" : "" ?>>
                                    选择代理级别
                                </option>
                                <option value="1" <?= isset($_GET['level']) && $_GET['level'] == 1 ? "selected" : "" ?> >
                                    招商经理
                                </option>
                                <option value="2" <?= isset($_GET['level']) && $_GET['level'] == 2 ? "selected" : "" ?> >
                                    一级代理
                                </option>
                                <option value="3" <?= isset($_GET['level']) && $_GET['level'] == 3 ? "selected" : "" ?> >
                                    二级代理
                                </option>
                                <option value="4" <?= isset($_GET['level']) && $_GET['level'] == 4 ? "selected" : "" ?> >
                                    普通顾客
                                </option>
                            </select>
                            <span class="am-form-caret"></span>
                        </div>
                        <div class="am-form-group am-fl" style="width: 200px">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                <input type="text" class="am-form-field" name="keyword"
                                       placeholder="请输入微信昵称"
                                       value="<?= isset($_GET['keyword']) ? $_GET['keyword'] : '' ?>">
                                <div class="am-input-group-btn">
                                    <button class="am-btn am-btn-default am-icon-search"
                                            type="submit"></button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>

                <div class="widget-body am-fr">
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>用户ID</th>
                                <th>微信头像</th>
                                <th>微信昵称</th>
                                <th>代理级别</th>
                                <th>手机号</th>
                                <th>性别</th>
                                <th>国家</th>
                                <th>省份</th>
                                <th>城市</th>
                                <th>注册时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['user_id'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= $item['avatarUrl'] ?>" title="点击查看大图" target="_blank">
                                            <img class="am-circle" src="<?= $item['avatarUrl'] ?>" width="56"
                                                 height="56" alt="">
                                        </a>
                                    </td>
                                    <td class="am-text-middle"><?= $item['nickName'] ?></td>
                                    <td class="am-text-middle"><?= $item['agentName'] ?></td>
                                    <td class="am-text-middle"><?= $item['mobile'] ?></td>
                                    <td class="am-text-middle"><?= $item['gender'] ?></td>
                                    <td class="am-text-middle"><?= $item['country'] ?: '--' ?></td>
                                    <td class="am-text-middle"><?= $item['province'] ?: '--' ?></td>
                                    <td class="am-text-middle"><?= $item['city'] ?: '--' ?></td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="javascript:void(0)" onclick="bindsub(<?=$item['user_id']?>)"
                                           class="am-btn-sm am-btn am-btn-default am-btn-success am-radius">选择</a>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="8" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var currentUserId = <?=$user['user_id']?>;

    function bindsub(userId) {
        var url = "<?= url('/store/user/set_sub/userId/')?>"+userId;
        $.ajax({
            url: url,
            dataType: 'json',
            type: 'post',
            data: {
                'to': <?=$user['user_id']?>
            },
            success: function (res) {

                console.log(res);
                if(res.code===1){
                    layer.confirm("设置成功", function (e) {
                        console.log(e);
                        history.go(0);
                    });

                }else{
                    layer.alert(res.msg);
                }
            }
        })
    }

    $(function () {

    });
</script>

